package com.ant.androiddemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.ant.androiddemo.constant.Global;

public class MainActivity extends AppCompatActivity {


    private static final String TAG = Global.LOG_TAG;
    private static final String SPF_TAG = Global.SPF_TAG;
    TextView tvAccount;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().setTitle("首页");
        tvAccount = findViewById(R.id.tv_account);
        initData();

    }

    private void initData(){
        //获取显示跳转
        Intent intent = getIntent();
        String account = intent.getStringExtra("account");
        tvAccount.setText("欢迎您：" + account);
    }

    public void fnLogout(View view) {
        SharedPreferences spf = getSharedPreferences(SPF_TAG, MODE_PRIVATE);
        SharedPreferences.Editor edit = spf.edit();
        edit.putBoolean("isLogin", false);
        edit.apply();

        Intent intent = new Intent(this, LoginActivity.class);
        startActivity(intent);
        this.finish();
    }

    public void toSetting(View view) {
        Intent intent = new Intent(this, UserActivity.class);
        startActivity(intent);
    }

    public void fnBaidu(View view) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("http://www.baidu.com"));
        startActivity(intent);
    }

    public void fnCamera(View view) {
        Log.d(TAG, "fnCamera: 卡死");
        Intent intent = new Intent();
        intent.setAction("android.media.action.IMAGE_CAPTURE");
        startActivity(intent);
    }

    public void fnPhoto(View view) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.PICK");
        intent.setType("image/*");
        startActivity(intent);
    }

    public void fnSms(View view) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("smsto:1313555"));
        intent.putExtra("sms_body", "你好啊，这是给你的短信");
        startActivity(intent);
    }

    public void fnCall(View view) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:1313555"));
        startActivity(intent);
    }

    //选项菜单
    public void toOptionsMenu(View view) {
        Intent intent = new Intent(this, OptionsMenuActivity.class);
        startActivity(intent);
    }

    //上下文菜单
    public void toContextMenu(View view) {
        Intent intent = new Intent(this, ContextMenuActivity.class);
        startActivity(intent);
    }
    //弹出式菜单
    public void toPopupMenu(View view) {
        Intent intent = new Intent(this, PopupMenuActivity.class);
        startActivity(intent);
    }

    public void toArrayListTest(View view) {
        Intent intent = new Intent(this, ArrayListActivity.class);
        startActivity(intent);
    }

    public void toSimpleListTest(View view) {

        Intent intent = new Intent(this, SimpleListActivity.class);
        startActivity(intent);
    }

    public void toBaseListTest(View view) {

        Intent intent = new Intent(this, BaseAdapterActivity.class);
        startActivity(intent);
    }

    public void toRecyclerTest(View view) {
        Intent intent = new Intent(this, RecyclerActivity.class);
        startActivity(intent);
    }

    public void insertData(View view) {
        Intent intent = new Intent(this, InsertActivity.class);
        startActivity(intent);
    }

    public void deleteData(View view) {
        Intent intent = new Intent(this, DeleteActivity.class);
        startActivity(intent);
    }


    public void updateData(View view) {
        Intent intent = new Intent(this, UpdateActivity.class);
        startActivity(intent);
    }

    public void queryData(View view) {
        Intent intent = new Intent(this, QueryActivity.class);
        startActivity(intent);
    }

    public void toMutiThread(View view) {
        Intent intent = new Intent(this, MutiThreadHandlerActivity.class);
        startActivity(intent);
    }
}